/*
 * ctensor.cpp
 *
 *  Created on: 27/08/2012
 *      Author: cvan680
 */

#include "ctensor.h"

#include <Eigen/Core>
#include <Eigen/Eigen>

namespace voreen {

CTensor::CTensor(float v11, float v12, float v21, float v22){
	this->t11 = v11;
	this->t12 = v12;
	this->t21 = v21;
	this->t22 = v22;
}

CTensor::~CTensor() { }
/*
tgt::vec2 CTensor::eigenVector(){
	//FIXME calculate eigenvector - Jacobian?

	using namespace Eigen;

	MatrixXf tmp = MatrixXf::Zero(2, 2);

	tmp(0,0) = this->t11;
	tmp(0,1) = this->t12;
	tmp(1,0) = this->t21;
	tmp(1,1) = this->t22;

    EigenSolver<MatrixXf> solver(tmp);

    MatrixXf eigenVectors = MatrixXf::Zero(2, 2);
    eigenVectors = solver.eigenvectors().real();

    tgt::vec2 ev(eigenVectors(0, 0), eigenVectors(0, 1));

    return ev;
}
tgt::vec3 CTensor::eigenVector3D(){
	tgt::vec2 ev = eigenVector();
	return tgt::vec3(ev.x, ev.y, 0.0);
}


CTensorField::CTensorField(tgt::ivec2 dimensions){
	this->dims = dimensions;
	this->tensorfield = new CTensor *[this->dims.y];
	for(int i=0; i < this->dims.y; i++){\
		this->tensorfield[i] = new CTensor *[this->dims.x];
	}
	/*
	for(int i=0; i < this->dims.x; i++){
		this->tensorfield[i] = new CTensor* [this->dims.x];
	}
	*/
/*
}
CTensorField::CTensorField(int xdimension, int ydimension){
	this->dims = new tgt::ivec2(xdimension, ydimension);
	this->tensorfield = new CTensor* [this->dims.y][this->dims.x];
}

void CTensorField::set(int x, int y, CTensor *t){
	if(x < 0 || x >= this->dims.x || y < 0 || y >= this->dims.y){ return 0; }
	this->tensorfield[x][y] = t;
}

CTensor CTensorField::get(int x, int y){
	if(x < 0 || x >= this->dims.x || y < 0 || y >= this->dims.y){ return 0; }
	return this->tensorfield[x][y];
}

void CTensorField::init(){
	for(int x=0; x<this->dims.x; x++){
		for(int y=0; y<this->dims.y; y++){
			this->tensorfield[x][y] = new CTensor(1.0, 0.0, 0.0, 1.0);
		}
	}
}

virtual CTensorField::~CTensorField(){ }
*/
}
